<template>
  <view class="content" >
    <uniPopup background-color="rgba(255,255,255,0)" ref="inputDialog"  type="dialog" >
      <div class="mboxContent">
          <div class="top">
            授权
          </div>
        <div class="main">
          <img src="/static/img/inputdialogIcons.png" alt="" class="rightimg">
          <div class="names">
            获得你的公开信息(昵称、头像等)
          </div>
          <div class="btn">
            <button class="success" @click="toRight">确认</button>
       
            
          </div>
        </div>
      
       
       
      </div>
        
            </uniPopup>
            
  </view>
</template>

<script>
   import dialogs from "@/components/dialog.vue";
import {decode,auth} from "@/utils/http"
import uniPopup from "@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue";
export default {
    components:{
    uniPopup,
    dialogs,
    
  },

  data() {
    return {
      isUse:true
    };
  },

  onLoad() {},
  methods: {
    toRight(){
 var that =this
    if(this.isUse){
      this.isUse =false
      uni.login({
        provider: "weixin",
        success: async function(loginRes) {
          let json = {
            code: loginRes.code,

          };
            decode(json).then(res=>{
              if(res.code == '0' &&res.result){
                uni.setStorageSync('openid',res.result)

                let form ={
                  openId:res.result,
                  userId:uni.getStorageSync('userInfo').userId,
                  name:''
                }
                auth(form).then(a=>{
                  if(a.code=='0'){
                    uni.setStorageSync('token',a.token)
                    this.isUse=true
                    if(uni.getStorageSync('userInfo').role =='admin' || uni.getStorageSync('userInfo').role == 'administrator'){
                      uni.reLaunch({
  url:'/pages/order/managerIndex'
})
                    }else {
                      uni.reLaunch({
  url:'/pages/order/index'
})
                    }
     
                  }
                }).finally(()=>{
                  this.isUse=true

                })
              }
            }).finally(()=>{
                  this.isUse=true

                })
      
        },
      });
    }
 
    },
    getPhoneNumber(e) {
      console.log(e,'eee')
      if(e.detail.errMsg =='getPhoneNumber:ok'){
        decode({code:e.detail.code}).then(res=>{
          
        })
        }

      // console.log(e, 'ee')
   
      
    },
    toClose(){
      this.$emit('closeAll',true)
      this.$refs.inputDialog.close()
    }
   
   
  },
};
</script>

<style scoped >

.mboxContent{
  text-align: center;
 
  background: white;
  box-sizing: content-box;
  /* padding:24px; */
  width: 540rpx;
  border-radius: 20px;

}
.top{
  font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: bold;
font-size: 34rpx;
color: #262626;
line-height: 24rpx;
font-style: normal;
box-sizing: border-box;
padding: 36rpx;
border-bottom: 2rpx solid #CBCBCB;
}
.main{
  min-height: 462rpx;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}
.names{
  font-family: SourceHanSansCN-Regular, SourceHanSansCN-Regular;
font-weight: normal;
font-size: 24rpx;
color: #707070;
line-height: 50rpx;
}
.mainText{
  font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: bold;
font-size: 34rpx;
color: #262626;
font-style: normal;
}
.rightimg{
width: 64rpx;
height: 64rpx;
margin:48rpx auto 32rpx
}
input{
  box-sizing: content-box;
  padding: 14rpx 9rpx;
  width: 430rpx;
  border: 1rpx solid #707070;
  background: #E9E9E9;
margin: 0 auto 0;
text-align: left;
  border-radius: 14rpx;
}

.btn{

border-radius: 32rpx 32rpx 32rpx 32rpx;
font-family: Source Han Sans CN, Source Han Sans CN;
font-weight: bold;
font-size: 32rpx;
color: #FFFFFF;
font-style: normal;
text-transform: none;
}
.success{
  width: 251rpx;
height: 64rpx;
background: #58BE6B;
border-radius: 32rpx 32rpx 32rpx 32rpx;
margin: 48rpx auto 0;
line-height: 64rpx;
border: none;
color: white;

}

</style>
  <style scoped>
  input >>> .inputP {
      color: #B7B7B7;
      font-family: SourceHanSansCN-Regular, SourceHanSansCN-Regular;
font-weight: normal;
font-size: 28rpx;
color: #B7B7B7;
}
</style>